package com.carpool.security.model;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import com.carpool.commons.spring.model.Auditable;

@Entity
@Table(name="users")
public class User implements Serializable, Auditable{

	 public static final int ACTIVE = 1;
	 public static final int INACTIVE = 0;
	 	@Id
	 	@Column(name = "USER_ID")
	    private long userId;
	   
	    @Column(name="USERNAME")
	    private String username;
	    
	 	@Column(name="PASSWORD")
	    private String password;
	   
	 	@Column(name = "FIRSTNAME")
	    private String firstName;
	 	
	 	@Column(name = "LASTNAME")
	    private String lastName;
	    
	 	@Column(name = "EMAIL")
	 	private String email;
	 	
	 	@Column(name = "ACTIVE")
	    private Integer active;
	//    private String timeZone;
	//    private String locale;
	    //join
	 	@ManyToMany(cascade =CascadeType.ALL)
	 	@JoinTable(name = "USER_ROLE", joinColumns = {@JoinColumn(name="USER_ID")},
	 			inverseJoinColumns = { @JoinColumn(name = "ROLE_ID") })
	    private Set roles;
	 	
	 	@ManyToMany(cascade =CascadeType.ALL)
	 	@JoinTable(name = "USER_GROUP", joinColumns = {@JoinColumn(name="USER_ID")},
	 			inverseJoinColumns = { @JoinColumn(name = "GROUP_ID") })
	    private Set groups;
	    //private Set employments;
	    //additional field
	    private String oldPassword;
	    private String confirmPassword;
	  //  private Boolean readonly = false;
	    
		public long getUserId() {
			return userId;
		}
		public void setUserId(long userId) {
			this.userId = userId;
		}
		public String getUsername() {
			return username;
		}
		public void setUsername(String username) {
			this.username = username;
		}
		public String getPassword() {
			return password;
		}
		public void setPassword(String password) {
			this.password = password;
		}
		public String getFirstName() {
			return firstName;
		}
		public void setFirstName(String firstName) {
			this.firstName = firstName;
		}
		public String getLastName() {
			return lastName;
		}
		public void setLastName(String lastName) {
			this.lastName = lastName;
		}
		public String getEmail() {
			return email;
		}
		public void setEmail(String email) {
			this.email = email;
		}
		public Integer getActive() {
			return active;
		}
		public void setActive(Integer active) {
			this.active = active;
		}
		public Set getRoles() {
			return roles;
		}
		public void setRoles(Set roles) {
			this.roles = roles;
		}
		public Set getGroups() {
			return groups;
		}
		public void setGroups(Set groups) {
			this.groups = groups;
		}
		public String getOldPassword() {
			return oldPassword;
		}
		public void setOldPassword(String oldPassword) {
			this.oldPassword = oldPassword;
		}
		public String getConfirmPassword() {
			return confirmPassword;
		}
		public void setConfirmPassword(String confirmPassword) {
			this.confirmPassword = confirmPassword;
		}
	    
		public String getAuditTrailId(){
			return username;
		}
}
